package com.juxing.webserver.action.front;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.juxing.sdk.util.DigestUtil;
import com.juxing.webserver.action.BaseAction;
import com.juxing.webserver.util.VerifyCodeUtils;

@Controller
@RequestMapping("front/common")
public class FrontCommonAction extends BaseAction {
	
	private static final Logger logger = LoggerFactory.getLogger(FrontCommonAction.class);
	
	/**
	 * 获取图片验证码key
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("getImgCodeKey.json")
	public ModelAndView getImgCodeKey(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = this.initSuccessView("front/common/getImgCodeKey");
		StringBuilder infoBuilder = new StringBuilder();
		infoBuilder.append(IMG_CODE_KEY_PREFIX);
		infoBuilder.append("_").append(System.currentTimeMillis());
		infoBuilder.append("_").append(VerifyCodeUtils.generateVerifyCode(4));
		String source = infoBuilder.toString();
		String imgCodeKey = DigestUtil.encrypt3Des(source, configManager.getImgCodeDigestBytes());
		view.addObject("imgCodeKey", imgCodeKey);
		return view;
	}
	
}
